<template>
  <uni-swipe-action>
    <uni-swipe-action-item>
  <view>
    <view class="goods-item" @click="gotoGoodsDetail">
      <!-- 商品左侧图片区域 -->
      <view class="goods-item-left">
        <radio :checked="goods.goods_state" @click.stop="radioClickHandel" color="#c00000" v-if="showRadio"></radio>
        <image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
      </view>
      <!-- 商品右侧信息区域 -->
      <view class="goods-item-right">
        <!-- 商品标题 -->
        <view class="goods-name">{{ goods.goods_name }}</view>
        <view class="goods-info-box">
          <!-- 商品价格 -->
          <view class="goods-price">￥{{ goods.goods_price | tifiexd }}</view>
          <uni-number-box v-if="showNum" @change="numChangehandle" :min="1" @click.native.stop="()=> {}" :value="goods.goods_count"></uni-number-box>
        </view>
      </view>
    </view>
  </view>
  <template v-slot:right>
  	<view class="slot-button"><text class="slot-button-text" @click="deleteGood">删除</text></view>
  </template>
  </uni-swipe-action-item>
  </uni-swipe-action>
</template>

<script>
  import { mapMutations } from 'vuex'
export default {
  name: 'my-good-list',
  props: {
    goods: {
      type: Object,
      required: true
    },
    showNum: {
      type: Boolean,
      default:false
    },
    // 控制radio显示与否
    showRadio:{
      type: Boolean,
      default:false
    }
  },
  filters: {
    tifiexd(num) {
      return Number(num).toFixed(2);
    }
  },
  data() {
    return {
      defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
    };
  },
  methods:{
    ...mapMutations('my-cart', ['deleteGoods']),
    deleteGood(){
      console.log('ni')
      this.deleteGoods({
        goods_id: this.goods.goods_id
      })
    },
    numChangehandle(val){
      console.log('val',val)
      this.$emit('detailCountChange',{
        goods_id:this.goods.goods_id,
        goods_count: val
      })
    },
    radioClickHandel(){
      this.$emit('isChange',{
        goods_id:this.goods.goods_id,
        goods_state:!this.goods.goods_state
      })
    },
    gotoGoodsDetail() {
      uni.navigateTo({
        url:'../../subpkg/goods_detail/goods_detail?goods_id='+ this.goods.goods_id
      })
    }
  }
};
</script>

<style lang="scss">
  
 .goods-info-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    margin-right: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }

  .goods-item-right {
    display: flex;
    flex: 1;
    flex-direction: column;
  justify-content: space-evenly;

    .goods-name {
      font-size: 13px;
    }

    .goods-price {
      font-size: 16px;
      color: #c00000;
    }
  }
}

.slot-button-text {
		color: #ffffff;
		font-size: 14px;
	}
  
  .slot-button {
        /* #ifndef APP-NVUE */
        display: flex;
        height: 100%;
        /* #endif */
        flex: 1;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 0 20px;
        background-color: #ff5a5f;
      }
    
</style>
